---
title: GitHub Actions for custom models
description: The custom models action manages custom inference models and deployments in DataRobot via GitHub CI/CD workflows.
---

# GitHub Actions for custom models  {: #github-actions-for-custom-models }

The custom models action manages custom inference models and their associated deployments in DataRobot via GitHub CI/CD workflows. These workflows allow you to create or delete models and deployments and modify settings. Metadata defined in YAML files enables the custom model action's control over models and deployments. Most YAML files for this action can reside in any folder within your custom model's repository. The YAML is searched, collected, and tested against a schema to determine if it contains the entities used in these workflows. For more information, see the [custom-models-action repository](https://github.com/datarobot-oss/custom-models-action){ target=_blank }.

## GitHub Actions quickstart {: #github-actions-quickstart }

This quickstart example uses a [Python Scikit-Learn model template](https://github.com/datarobot/datarobot-user-models/tree/master/model_templates/python3_sklearn){ target=_blank } from the [datarobot-user-model repository](https://github.com/datarobot/datarobot-user-models/tree/master/model_templates){ target=_blank }. To set up a custom models action that will create a custom inference model and deployment in DataRobot from a custom model repository in GitHub, take the following steps:

1. In the `.github/workflows` directory of your custom model repository, create a YAML file (with any filename) containing the following:

    {% raw %}
    ```yaml linenums="1" hl_lines="5 7 29 30 31"
    name: Workflow CI/CD

    on:
      pull_request:
        branches: [ master ]
      push:
        branches: [ master ]

      # Allows you to run this workflow manually from the Actions tab
      workflow_dispatch:

    jobs:
      datarobot-custom-models:
        # Run this job on any action of a PR, but skip the job upon merging to the main branch. This
        # will be taken care of by the push event.
        if: ${{ github.event.pull_request.merged != true }}

        runs-on: ubuntu-latest

        steps:
          - uses: actions/checkout@v3
            with:
              fetch-depth: 0

          - name: DataRobot Custom Models Step
            id: datarobot-custom-models-step
            uses: datarobot-oss/custom-models-action@v1.4.0
            with:
              api-token: ${{ secrets.DATAROBOT_API_TOKEN }}
              webserver: https://app.datarobot.com/
              branch: master
              allow-model-deletion: true
              allow-deployment-deletion: true
    ```
    {% endraw %}
    
    Configure the following fields:

    * `branches`: Provide the name of your repository's main branch (usually either `master` or `main`) for `pull_request` and `push`. If you created your repository in GitHub, you likely need to update these fields to `main`. While `master` and `main` are the most common branch names, you can target any branch; for example, you could run the workflow on a `release` branch or a `test` branch.

    * `api-token`: Provide a value for the `DATAROBOT_API_TOKEN` variable by creating an [encrypted secret for GitHub Actions](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository){ target=_blank } containing your [DataRobot API key](api-key-mgmt#api-key-management). Alternatively, you can set the token string directly to this field; however, this method is highly discouraged because your API key is extremely sensitive data. If you use this method, anyone who has access to your repository can access your API key.

    * `webserver`: Provide your DataRobot webserver value here if it isn't the default DataRobot US server (`https://app.datarobot.com/`).

    * `branch`: Provide the name of your repository's main branch (usually either `master` or `main`). If you created your repository in GitHub, you likely need to update this field to `main`. While `master` and `main` are the most common branch names, you can target any branch; for example, you could run the workflow on a `release` branch or a `test` branch.

2. Commit the workflow YAML file and push it to the remote. After you complete this step, any push to the remote (or merged pull request) triggers the action.

3. In the folder for your DataRobot custom model, add a model definition YAML file (e.g., `model.yaml`) containing the following YAML and update the field values according to your model's characteristics:

    ```yaml
    user_provided_model_id: user/model-unique-id-1
    target_type: Regression
    settings:
      name: My Awesome GitHub Model 1 [GitHub CI/CD]
      target_name: Grade 2014

    version:
      # Make sure this is the environment ID is in your system.
      # This one is the '[DataRobot] Python 3 Scikit-Learn Drop-In' environment
      model_environment_id: 5e8c889607389fe0f466c72d
    ```
    Configure the following fields:

    * `user_provided_model_id`: Provide any descriptive and unique string value. DataRobot recommends following a naming pattern, such as `<user>/<model-unique-id>`.

        !!! note
            By default, this ID will reside in a unique namespace, the GitHub repository ID. Alternatively, you can configure the namespace as an input argument to the custom models action.

    * `target_type`: Provide the correct target type for your custom model.

    * `target_name`: Provide the correct target name for your custom model.

    * `model_environment_id`: Provide the DataRobot execution environment required for your custom model. You can find these environments in the DataRobot application under [**Model Registry** > **Custom Model Workshop** > **Environments**](custom-environments).

        ![](images/pp-cus-model-github3.png)

4. In any directory in your repository, add a deployment definition YAML file (with any filename) containing the following YAML:

    ```yaml
    user_provided_deployment_id: user/my-awesome-deployment-id
    user_provided_model_id: user/model-unique-id-1
    ```

    Configure the following fields:

    * `user_provided_deployment_id`: Provide any descriptive and unique string value. DataRobot recommends following a naming pattern, such as `<user>/<deployment-unique-id>`.

        !!! note
            By default, this ID will reside in a unique namespace, the GitHub repository ID. Alternatively, you can configure the namespace as an input argument to the custom models action.

    * `user_provided_model_id`: Provide the exact `user_provided_model_id` you set in the model definition YAML file.

5. Commit these changes and push to the remote, then:

    * Navigate to your custom model repository in GitHub and click the `Actions` tab. You'll notice that the action is being executed.

    * Navigate to the DataRobot application. You'll notice that a new custom model was created along with an associated deployment. This action can take a few minutes.

!!! warning
    Creating two commits (or merging two pull requests) in quick succession can result in a `ResourceNotFoundError`. For example, you add a model definition with a training dataset, make a commit, and push to the remote. Then, you immediately delete the model definition, make a commit, and push to the remote. The training data upload action may begin after model deletion, resulting in an error. To avoid this scenario, wait for an action's execution to complete before pushing new commits or merging new pull requests to the remote repository.

## Access commit information in DataRobot {: #access-commit-information-in-DataRobot }

After your workflow creates a model and a deployment in DataRobot, you can access the commit information from the model's version info and the deployment's overview:

=== "Model version info"

    1. In the **Model Registry**, click **Custom Model Workshop**.

    2. On the **Models** tab, click a GitHub-sourced model from the list and then click the **Versions** tab.

    3. Under **Manage Versions**, click the version you want to view the commit for.

    4. Under **Version Info**, find the **Git Commit Reference** and then click the commit hash (or commit ID) to open the commit that created the current version.

      ![](images/pp-cus-model-github2.png)

=== "Model package info"

    1. In the **Model Registry**, click **Model Packages**.
    
    2. On the **Model Packages** tab, click a GitHub-sourced model package from the list.

    3. Under **Package Info**, review the model information provided by your workflow, find the **Git Commit Reference**, and then click the commit hash (or commit ID) to open the commit that created the current model package.

      ![](images/pp-cus-model-github4.png)

=== "Deployment overview"

    1. In the **Deployments** inventory, click a GitHub-sourced deployment from the list.

    2. On the deployment's **Overview** tab, review the model and deployment information provided by your workflow.

    3. In the **Content** group box, find the **Git Commit Reference** and click the commit hash (or commit ID) to open the commit that created the deployment.

    ![](images/pp-cus-model-github1.png)

